package com.yun.baymax.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.yun.baymax.R;
import com.yun.baymax.utils.SaveFileUtils;
import com.yun.baymax.utils.ToastUtils;
import com.yun.lib.utils.StatusBarUtils;

/**
 * download and show original image
 */
public class ShowImageActivity extends BaseActivity {
    private ImageView back;
    private ImageView image;
    private ImageView download;
    private String uri;

    @Override
    protected int setLayoutResourceId() {
        StatusBarUtils.setWindowStatusBarColor(this, R.color.black);
        return R.layout.activity_show_image;
    }

    @Override
    protected void initVariables() {
        uri = getIntent().getStringExtra("uri");
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        back = (ImageView) findViewById(R.id.back);
        download = (ImageView) findViewById(R.id.download);
        image = (ImageView) findViewById(R.id.image);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Glide.with(mContext).load(uri).asBitmap().into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        boolean isSuccess = SaveFileUtils.saveImageToGallery(mContext, resource);
                        if (isSuccess)
                            ToastUtils.showShortToast("保存成功");
                    }
                });
            }
        });
        Glide.with(mContext).load(uri).into(image);
    }

    @Override
    protected void loadData() {

    }
}
